import {createRouter, createWebHistory} from 'vue-router';
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
import defaultRouters from '@/scripts/router/defaultRouters';

const routerHistory = createWebHistory();

let vueRouter = createRouter({
    history: routerHistory,
    routes: defaultRouters,
    scrollBehavior: () => ({y: 0}),
});

//监听路由
vueRouter.beforeEach((to, from, next) => {
    NProgress.start();
    console.log('路由拦截器=>', from, to);
    next();
});

vueRouter.afterEach(() => {
    NProgress.done();
});

export default vueRouter